import { Inject, Controller, Post, Body } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { LoginService } from '../service/login.service';

@Controller('/login')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  loginService: LoginService;

  @Post('/')
  async login(@Body('name') name, @Body('password') password) {
    const user = await this.loginService.login({ name, password });

    return {
      success: true,
      message: 'OK',
      data: {
        ...user,
      },
    };
  }
}
